const sequelize = require('../config/database');
const Student = require('./Student');
const Score = require('./Score');
const ImportLog = require('./ImportLog');
const StudentAnalysis = require('./StudentAnalysis');
const AIModel = require('./AIModel');

// 定义关联关系
Student.hasMany(Score, {
  foreignKey: 'student_id',
  sourceKey: 'student_id',
  as: 'scores'
});

Score.belongsTo(Student, {
  foreignKey: 'student_id',
  targetKey: 'student_id',
  as: 'student'
});

// 学生与分析报告的关联
Student.hasOne(StudentAnalysis, {
  foreignKey: 'student_id',
  sourceKey: 'student_id',
  as: 'analysis'
});

StudentAnalysis.belongsTo(Student, {
  foreignKey: 'student_id',
  targetKey: 'student_id',
  as: 'student'
});

module.exports = {
  sequelize,
  Student,
  Score,
  ImportLog,
  StudentAnalysis,
  AIModel
};
